# -*- coding: utf-8 -*-

import cProfile
import pstats

from py_research.py_performance.py_profile import fibonacci_sequence


def py_cprofile():
    cProfile.run('write_aline("logs/1.log", datetime.datetime.now().strftime("%Y-%m-%d"))')
    pass


def do_c_profile(filename):
    def decorator(func):
        def wrapper(*args, **kwargs):
            profile = cProfile.Profile()
            profile.enable()
            result = func(*args, **kwargs)
            profile.disable()

            ps = pstats.Stats(profile).sort_stats("tottime")
            ps.dump_stats(filename)
            return result

        return wrapper

    return decorator


@do_c_profile("prof.prof")
def be_c_profile():
    # write_aline("logs/1.log", datetime.datetime.now().strftime("%Y-%m-%d"))

    fibonacci_sequence(3)

    pass


if __name__ == '__main__':

    """
    python -m cProfile -o prof.prof py_c_profile.py
    runsnake prof.prof
    """
    be_c_profile()

    pass
